package org.jspar.matrix;

import org.jspar.model.Net;
import org.jspar.model.NetList;
import org.jspar.model.Terminal;

public class UnsignedMatrixBuilder implements IMatrixBuilder {

	public UnsignedMatrixBuilder() { }

	public ConnectionMatrix build(NetList netList) {
		ConnectionMatrix matrix = new ConnectionMatrix(netList.modules());
		Net[] nets = netList.nets();

		for (int i = 0; i < nets.length; ++i) {
			Terminal[] terms = nets[i].terminals();
			for (int j = 0; j < terms.length; ++j) {
				for (int k = 0; k < terms.length; ++k) {
					if (terms[j].module() != terms[k].module()) {
						matrix.incrementAt(terms[j].module(),
								terms[k].module());
						matrix.incrementAt(terms[j].module(),
								terms[j].module());
					}
				}
			}
		}
		return matrix;
	}
}
